package com.wc.codeforces.贪心.Sharky_Surfing;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/11/17 23:09
 * @description
 * https://codeforces.com/contest/2037/problem/D
 */
public class Main {
    /**
     * 障碍前面的都可以用, 如果不够, 就取最大的, 然后过
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static PriorityQueue<Integer> heap = new PriorityQueue<>(Comparator.reverseOrder());
    static int[][] xv = new int[N][2], lr = new int[N][2];
    static int n, m, L;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0){
            heap.clear();
            n = sc.nextInt();
            m = sc.nextInt();
            L = sc.nextInt();
            for (int i = 1; i <= n; i++) {
                lr[i][0] = sc.nextInt();
                lr[i][1] = sc.nextInt();
            }
            for (int i = 1; i <= m; i++) {
                xv[i][0] = sc.nextInt();
                xv[i][1] = sc.nextInt();
            }
            Arrays.sort(xv, 1, m + 1, Comparator.comparingInt(o -> o[0]));
            int res = 0, power = 1;
            for (int i = 1, j = 1; i <= n; i++){
                while (j <= m && xv[j][0] < lr[i][0]) heap.add(xv[j++][1]);
                int sum = lr[i][1] - lr[i][0] + 2;
                while (!heap.isEmpty() && power < sum) {
                    power += heap.poll();
                    res++;
                }
                if (power < sum) {
                    res = -1;
                    break;
                }
            }
            out.println(res);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

